package Test;

import java.util.Scanner;

public class Test {
    public static void main(String[] args) {
        System.out.println(Sum(10,20));
        System.out.println(Sum(20,20));
        System.out.println(Sum(300,20));

        System.out.println("---------------");

        int a = 10, b = 20;
        int[] arr = {a,b};
        System.out.println("a="+arr[0]+", "+"b="+arr[1]);
        Swap(arr);
        System.out.println("a="+arr[0]+", "+"b="+arr[1]);

        System.out.println("输出1—n的和：");
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        System.out.println(Sum_n(n));
    }

    //java方法定义
    public static int Sum(int a, int b)
    {
        return a+b;
    }

    public static void Swap(int[] arr)
    {
        int tmp = arr[0];
        arr[0] = arr[1];
        arr[1] = tmp;
    }

    public static int Sum_n(int n)
    {
        int sum = 0;
        for (int i = 0; i <= n; i++) {
            sum += i;
        }

        return sum;
    }
}
